﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FortuneHeaven.Admin.Common;
using FortuneHeavenCommon.DataMap;
using FortuneHeavenBAL;
using System.Text;

namespace FortuneHeaven.Admin.Pages.GameManager
{
    public partial class SpecialRegister : FortuneHeaven.Admin.Common.PageBase
    {
        public int IsSp = 0;
        public override string PageID
        {
            get { return "F58"; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            lblDeptName.Text = "推广页面注册用户";
            this.usPager.PagerChanged += new Admin.Controls.Pagination.PagerChangeHandler(usPager_PagerChanged);
         
            if (!this.IsPostBack)
            {
                this.drpPagerSize.Items.Clear();
                this.drpPagerSize.Items.Add(new ListItem("每页10行", "10"));
                this.drpPagerSize.Items.Add(new ListItem("每页20行", "20"));
                this.drpPagerSize.Items.Add(new ListItem("每页50行", "50"));
                //this.drpFromPage.Items.Add(new ListItem("全部", "全部"));
                //this.drpFromPage.Items.Add(new ListItem("Index.aspx" , "Index.aspx" ));
                //for (int i = 1; i <= 9; i++)
                //{
                //    this.drpFromPage.Items.Add(new ListItem("Index" + i.ToString() + ".aspx", "Index" + i.ToString() + ".aspx"));
                //}
                AdminUserBO bo = new AdminUserBO();
                AdminUser user = bo.GetInfo(AuthorityCenter.CurrentUserID);
                if (!AuthorityCenter.IsAdmin)
                {
                    this.drpFromPage.SelectedValue = user.IndexFilter;
                    this.drpFromPage.Enabled = false;
                }
                if (!string.IsNullOrEmpty(Request["id"]))
                {
                    this.txtOrderID.Text = Request["id"];
                }


                if (!string.IsNullOrEmpty(Request["pagesize"]))
                {
                    this.drpPagerSize.SelectedIndex = int.Parse(Request["pagesize"]);
                }
                else
                {
                    this.drpPagerSize.SelectedValue = "10";
                }

              
                if (!string.IsNullOrEmpty(Request["user"]))
                {
                    this.txtOrderID.Text = Request["user"];
                }

                if (!string.IsNullOrEmpty(Request["current"]))
                {
                    ResetList(int.Parse(Request["current"]));
                }
                else
                {
                    ResetList();
                }


                //this.lvNews.ItemCommand += new EventHandler<ListViewCommandEventArgs>(lvNews_ItemCommand);

            }

            GetCurrent();
        }

        public int GetCurrent()
        {   
            string sel = this.drpFromPage.SelectedValue;
            
            if (sel == "全部" || AuthorityCenter.IsAdmin)
            {
                IsSp = 0;
                return IsSp;
            }
            if (sel == "Index.aspx"
                || sel == "Index1.aspx"
                 || sel == "Index2.aspx"
                 || sel == "Index3.aspx"
                 || sel == "Index4.aspx"
                )
            {
                IsSp = 1;
                return IsSp;
            }

            IsSp = 2;
            return IsSp;
        }
        private void usPager_PagerChanged(object sender, int currentpage)
        {
            Refresh();
        }

        public void Refresh()
        {
            UserInforBO acount = new UserInforBO();
            lvNews1.DataSource = acount.GetSpecialRegisterList(this.usPager.CurrentPageIndex, int.Parse(this.drpPagerSize.SelectedValue), this.txtOrderID.Text, this.drpFromPage.SelectedValue);
            lvNews1.DataBind();
        }

        protected void drpPagerSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            ResetList();
        }

        protected void drpFromPage_SelectedIndexChanged(object sender, EventArgs e)
        {
            ResetList();
        }

        public void ResetList()
        {
            ResetList(1);
        }

        public void SearchValue(object sender, EventArgs e)
        {
            ResetList();
        }

        public void ResetList(int current)
        {
            UserInforBO acount = new UserInforBO();
            this.usPager.RecordCount = acount.GetSpecialRegisterTotalSize(this.txtOrderID.Text, this.drpFromPage.SelectedValue);
            this.usPager.PageSize = int.Parse(this.drpPagerSize.SelectedValue);
            this.usPager.Initial();
            this.usPager.CurrentPageIndex = 1;
        }

        public string GetCorrectShow(object RechargeValue, object GameUsedScore)
        {
            GetCurrent();
            StringBuilder builder = new StringBuilder();
            if (IsSp == 0)
            {
                builder.AppendLine("<td>");
                builder.AppendLine(RechargeValue.ToString());
                builder.AppendLine("</td>");
                builder.AppendLine("<td>");
                builder.AppendLine(GameUsedScore.ToString());
                builder.AppendLine("</td>");
            }
            if (IsSp == 1)
            {
                builder.AppendLine("<td>");
                builder.AppendLine(RechargeValue.ToString());
                builder.AppendLine("</td>");
               
            }
            if (IsSp == 2)
            {
                builder.AppendLine("<td>");
                builder.AppendLine(GameUsedScore.ToString());
                builder.AppendLine("</td>");
            }
            return builder.ToString();
        }
    }
}